From 3bc33badf2f2afcb61dca3ee5446e4c13f0c26b4 Mon Sep 17 00:00:00 2001 From: Steven Hand Date: Wed, 27 Jun 2007 21:01:08 +0100 Subject: [PATCH] Add new sysctl to return runtime information about physical CPU utilization. Signed-off-by: Steven Hadn --- tools/libxc/xc_misc.c | 19 +++++++++++++++++++ tools/libxc/xenctrl.h | 2 ++ xen/common/schedule.c | 8 ++++++-- xen/common/sysctl.c | 32 ++++++++++++++++++++++++++++++++ xen/include/public/sysctl.h | 13 +++++++++++++ 5 files changed, 72 insertions(+), 2 deletions(-) diff --git a/tools/libxc/xc_misc.c b/tools/libxc/xc_misc.c index 987eb0eb13..e17bf7f721 100644 --- a/tools/libxc/xc_misc.c +++ b/tools/libxc/xc_misc.c @@ -109,6 +109,25 @@ int xc_perfc_control(int xc_handle, return rc; } +int xc_cpuinfo(int xc_handle, int max_cpus, uint64_t *info, int *nr_cpus) +{ + int ret; + DECLARE_SYSCTL; + + sysctl.cmd = XEN_SYSCTL_cpuinfo; + sysctl.u.cpuinfo.max_cpus = max_cpus; + set_xen_guest_handle(sysctl.u.cpuinfo.buffer, info); + + if ( (ret = do_sysctl(xc_handle, &sysctl)) != 0 ) + return ret; + + if(nr_cpus) + *nr_cpus = sysctl.u.cpuinfo.nr_cpus; + + return 0; +} + + int xc_hvm_set_pci_intx_level( int xc_handle, domid_t dom, uint8_t domain, uint8_t bus, uint8_t device, uint8_t intx, diff --git a/tools/libxc/xenctrl.h b/tools/libxc/xenctrl.h index df71417c7e..26325f0c46 100644 --- a/tools/libxc/xenctrl.h +++ b/tools/libxc/xenctrl.h @@ -479,6 +479,8 @@ int xc_physinfo(int xc_handle, int xc_sched_id(int xc_handle, int *sched_id); +int xc_cpuinfo(int xc_handle, int max_cpus, uint64_t *info, int *nr_cpus); + int xc_domain_setmaxmem(int xc_handle, uint32_t domid, unsigned int max_memkb); diff --git a/xen/common/schedule.c b/xen/common/schedule.c index 7911f5f99c..17443a44f4 100644 --- a/xen/common/schedule.c +++ b/xen/common/schedule.c @@ -72,8 +72,12 @@ static inline void vcpu_runstate_change( ASSERT(v->runstate.state != new_state); ASSERT(spin_is_locked(&per_cpu(schedule_data,v->processor).schedule_lock)); - v->runstate.time[v->runstate.state] += - new_entry_time - v->runstate.state_entry_time; + if(unlikely((v->runstate.state_entry_time - new_entry_time) > TIME_SLOP)) + /* Local time on this CPU has been warped */ + v->runstate.time[v->runstate.state] = new_entry_time; + else + v->runstate.time[v->runstate.state] += + new_entry_time - v->runstate.state_entry_time; v->runstate.state_entry_time = new_entry_time; v->runstate.state = new_state; } diff --git a/xen/common/sysctl.c b/xen/common/sysctl.c index 0cba2c1164..28cbf9b71f 100644 --- a/xen/common/sysctl.c +++ b/xen/common/sysctl.c @@ -136,6 +136,38 @@ long do_sysctl(XEN_GUEST_HANDLE(xen_sysctl_t) u_sysctl) } break; + case XEN_SYSCTL_cpuinfo: + { + uint32_t i, nr_cpus; + uint64_t idletime; + + nr_cpus = (op->u.cpuinfo.max_cpus > NR_CPUS) ? NR_CPUS : + op->u.cpuinfo.max_cpus; + + for ( i = 0; i < nr_cpus; i++ ) + { + if(!idle_vcpu[i]) + /* XXX: assumes no further CPUs after first missing one */ + break; + + /* somewhat imprecise but should suffice */ + idletime = idle_vcpu[i]->runstate.time[RUNSTATE_running] + + (NOW() - idle_vcpu[i]->runstate.state_entry_time); + if ( copy_to_guest_offset(op->u.cpuinfo.buffer, i, &idletime, 1) ) + { + ret = -EFAULT; + break; + } + } + + op->u.cpuinfo.nr_cpus = i; + ret = 0; + + if( copy_to_guest (u_sysctl, op, 1) ) + ret = -EFAULT; + } + break; + default: ret = arch_do_sysctl(op, u_sysctl); break; diff --git a/xen/include/public/sysctl.h b/xen/include/public/sysctl.h index e18d7243f6..be20efc4c1 100644 --- a/xen/include/public/sysctl.h +++ b/xen/include/public/sysctl.h @@ -152,6 +152,18 @@ struct xen_sysctl_debug_keys { typedef struct xen_sysctl_debug_keys xen_sysctl_debug_keys_t; DEFINE_XEN_GUEST_HANDLE(xen_sysctl_debug_keys_t); +/* Get physical CPU information */ +#define XEN_SYSCTL_cpuinfo 8 +struct xen_sysctl_cpuinfo { + /* IN variables. */ + uint32_t max_cpus; + XEN_GUEST_HANDLE_64(uint64_t) buffer; + /* IN/OUT variables. */ + uint32_t nr_cpus; +}; +typedef struct xen_sysctl_cpuinfo xen_sysctl_cpuinfo_t; +DEFINE_XEN_GUEST_HANDLE(xen_sysctl_cpuinfo_t); + struct xen_sysctl { uint32_t cmd; uint32_t interface_version; /* XEN_SYSCTL_INTERFACE_VERSION */ @@ -163,6 +175,7 @@ struct xen_sysctl { struct xen_sysctl_perfc_op perfc_op; struct xen_sysctl_getdomaininfolist getdomaininfolist; struct xen_sysctl_debug_keys debug_keys; + struct xen_sysctl_cpuinfo cpuinfo; uint8_t pad[128]; } u; }; -- 2.30.2